<?php
/**********************************************************************//**\file
	Armory Stats

	Description:  Displays statistics about the script itself, such as the
		update frequency, number of records the database, etc.
*******************************************************************************/

	require_once('core/core.php');

	echo '<?xml version="1.0" encoding="UTF-8" ?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>fetch-armory Diagnostic Statistics</title>
<style type="text/css">
	body {
		background-color: #222;
		color: #fff;
		font-size: .85em;
		font-family: Arial, sans-serif;
	}
	div#stats {
		max-width: 580px;
		margin: auto;
	}
	span {
		color: #0f0;
		font-weight: bold;
	}
</style>
</head>
<body>
	<div id="stats">
		<h1>fetch-armory Diagnostic Statistics</h1>
<?php
	$db = new armorydb();

	$db->query("SELECT COUNT(*) FROM armory_player");
	$total_users = $db->quick_result();
	echo "There are <span>$total_users</span> total characters in the database.<br />";

	$db->query("SELECT runtime_value FROM armory_runtime WHERE runtime_name = 'last_run'");
	$last_run = intval($db->quick_result());
	echo "The script was last run at <span>".date('r', $last_run)."</span>.<br />";

	$db->query("SELECT runtime_value FROM armory_runtime WHERE runtime_name = 'last_wowarmory'");
	$last_wowarmory = intval($db->quick_result());
	echo "Last guild roster pull took place at <span>".date('r', $last_wowarmory)."</span>.<br />";

	$db->query("SELECT runtime_value FROM armory_runtime WHERE runtime_name = 'last_wowheroes'");
	$last_wowheroes = intval($db->quick_result());
	echo "Last wowheroes pull took place at <span>".date('r', $last_wowheroes)."</span>.<br />";

	$db->query("SELECT player_name, player_updated FROM armory_player WHERE player_updated != 0 ORDER BY player_updated DESC LIMIT 45");
	$players = $db->multi_result();

	echo '<h3>Last 45 profiles updated</h3>';
	echo '<table style="border: 1px solid #444; padding: 5px; width: 100%;">';
	$current = 1;
	foreach($players as $var)
	{
		echo '<tr><td>#'.$current.'</td><td>'.utf8_encode($var['player_name']).'</td><td>'.date('r', $var['player_updated']).'</td></tr>';
		$current++;
	}
	echo '</table>';

	$twodaysago = time() - 172800;
	$db->query("SELECT COUNT(*) FROM armory_player WHERE player_updated > $twodaysago");
	$recent = intval($db->quick_result());
	echo "<br /><span>$recent (".intval($recent/$total_users*100)."%)</span> profiles have been updated in the past 48 hours.<br />";

	$db->query("SELECT COUNT(*) FROM armory_player WHERE player_updated < $twodaysago AND player_updated != 0");
	$decayed_records = intval($db->quick_result());
	echo "There are <span>$decayed_records (".intval($decayed_records/$total_users*100)."%)</span> profiles with expired data.<br />";

	$db->query("SELECT COUNT(*) FROM armory_player WHERE player_updated = 0");
	$records_in_queue = intval($db->quick_result());
	echo "There are <span>$records_in_queue (".intval($records_in_queue/$total_users*100)."%)</span> profiles with non-verbose data.<br />";
	
?>
	</div>
</body>
</html>